

###
### DECENT LIVING STANDARDS MAPPING 
### 

###
### DESCRIPTIVE GRAPHS 
### 

rm(list=ls())#; .rs.restartR()


##
## PACKAGES --------------------------------------------------------------
##

library(tidyverse)


## SET WORKING DIRECTORY -------------------------------------------------

#> set working directory to p drive here

#setwd("P:/just")


##
## LOADING DATA ----------------------------------------------------------
##

load(file="Complete DLS data file_regional level.RData")

##
## GEOM POINTRANGE PLOT SHOWING AVAILABILITY OF DATA
## 


dls_region <- dls_region %>% 
  group_by(country_name, wave, worldregion)  %>%
  group_by(country_name) %>% 
  mutate(wave_min = min(as.numeric(wave)), wave_max = max(as.numeric(wave))) %>% 
  ungroup() %>% 
  mutate(order=recode(worldregion, 
                      "Sub-Saharan Africa"=1L,
                      "Latin America & Caribbean"=2L,
                      "East Asia & Pacific"=3L,
                      "South Asia"= 4L,
                      "Europe & Central Asia" = 5L,
                      "Middle East & North Africa"=6L
                      
  ))


dls_region <- dls_region %>% 
  filter(!is.na(dls_index)) 

dls_region %>% 
  ggplot()+
  geom_point(aes(y=fct_reorder(country_name, -order),x=as.numeric(wave), 
                 color=fct_reorder(worldregion, order)))+
  geom_segment(aes(x=wave_min, xend=wave_max, 
                   y=country_name, 
                   yend=country_name, 
                   color=worldregion))+
  ylab("")+xlab("DHS Wave")+
  theme_bw()+
  labs(color="worldregion")+
  theme(legend.position = "right")+
  scale_color_brewer(palette= "Dark2")+
  guides(color=guide_legend(title="World region"))+
  theme(legend.title = element_text(size=16),
        legend.text = element_text(size=14),
        axis.text=element_text(size=12),
        axis.title = element_text(size=14))

ggsave("supplementary figure s1.png", width = 12, height=12)
ggsave("supplementary figure s1.svg", width = 12, height=12)




